<!DOCTYPE html>
<html lang="en">
<!-- 文字雨特效 --> 
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>文字雨特效</title>
  <style>
    body {
      padding: 0;
      margin: 0;
      width: 100vw;
      height: 100vh;
      background: linear-gradient(to bottom, #fbc8d4 0%, #9795f0 100%);
      justify-content: center;
      align-items: center;
      display: flex;
    }

    .shell {
      position: relative;
      height: 560px;
      -webkit-box-reflect: below 1px linear-gradient(transparent, transparent, transparent, transparent, #0005);
    }

    .cloud {
      position: relative;
      top: 50px;
      width: 320px;
      height: 300px;
      background-image: url("img/03.png") ;
      background-size: cover;
    }

    .text {
      position: absolute;
      top: 250px;
      line-height: 20px;
      color: white;
      text-shadow: 0 0 5px #fff, 0 0 15px #fff, 0 0 30px #fff;
      animation: rain 1s linear forwards;
    }

    @keyframes rain {
      0% {
        transform: translateY(0) scale(1);
      }

      80% {
        transform: translateY(230px) scale(1);
      }

      100% {
        transform: translateY(220px) scale(1.3);
        opacity: 0;
      }
    }
  </style>
</head>

<body>
<div class="shell">
  <div class="cloud"></div>
</div>
</body>
<script>
  function randomText(text) {
    return text[Math.floor(Math.random() * text.length)];
  }
  function rain() {
    const cloud = document.querySelector('.cloud');
    const e = document.createElement('div');
    const left = Math.floor(Math.random() * 310)
    const size = Math.random() * 1.5
    const duration = Math.random()
    const text = randomText('我爱你')
    e.classList.add('text')
    e.innerText = text;
    e.style.left = left + 'px'
    e.style.fontSize = 0.5 + size + 'em'
    e.style.animationDuration = 1 + duration + 's'
    cloud.appendChild(e)
    setTimeout(() => {
      cloud.removeChild(e)
    }, 2000)
  }
  setInterval(rain, 20)
</script>

</html>